﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LeanEngine.Reflection;
using System.Data.Linq.Mapping;

namespace LeanEngine.Entity
{
    public struct MetaTable
    {
        #region Constructor Members

        public MetaTable(Type entityType)
            : this()
        {
            var tableAttribute = entityType.GetCustomAttributes(typeof(TableAttribute), false).First() as TableAttribute;
            
            this.EntityType = entityType;
            this.TableName = tableAttribute == null ? string.Empty : tableAttribute.Name;
            this.ColumnsList = from p in entityType.GetProperties()
                               where p.GetCustomAttributes(typeof(ColumnAttribute), false).Count() > 0
                              select new MetaColumn(p);
        }

        #endregion

        #region PropertyInfo Members

        public string TableName { get; private set; }
        public Type EntityType { get; private set; }
        public IEnumerable<MetaColumn> ColumnsList { get; private set; }

        #endregion
    }
}
